<template>
  <div
    v-loading="loading"
    class="bbg-white p-4 rounded"
  >
    <el-form
      :model="form"
      label-width="160px"
    >
      <el-form-item label="物流查询key">
        <div>
          <el-input
            v-model="form.ship"
            placeholder="物流查询key"
          >
          </el-input>
          <small class="text-gray-500 flex mt-1 ml-1">
            用于查询物流信息，接口申请（仅供参考）
          </small>
        </div>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          size="default"
          @click="submit"
        >
          保存
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, reactive } from "vue";
import { getSysconfig, setSysconfig } from "~/api/sysconfig.js";
import { toast } from "~/composables/util.js";

const form = reactive({
  ship: "",
});

const loading = ref(false);
function getData() {
  loading.value = true;
  getSysconfig()
    .then((res) => {
      console.log("获取原有系统设置:", res);
      // res有多余的属性，我们只要给需要的属性赋值
      for (const k in form) {
        form[k] = res[k];
      }
    })
    .finally(() => {
      loading.value = false;
    });
}
getData();
const submit = () => {
  loading.value = true;
  setSysconfig({
    ...form,
  })
    .then((res) => {
      toast("修改成功！");
      getData();
    })
    .finally(() => {
      loading.value = false;
    });
};
</script>
